/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.retail;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import database.TOrderDAO;
import java.util.List;
import java.util.Map;
import model.Customer;
import model.Order;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Thai Ha Cong
 */
@Namespace("/Member")
public class MemberLinkAction extends ActionSupport {
    
    private List<Order> orderList;
    
    public MemberLinkAction() {
    }

    public List<Order> getOrderList() {
        return orderList;
    }

    public void setOrderList(List<Order> orderList) {
        this.orderList = orderList;
    }
    
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }
    
    @Action(value = "loginForm", results = {
        @Result(name = "success", location = "/member/login.jsp")
    })
    public String login() {
        return SUCCESS;
    }
    
    @Action(value = "registerForm", results = {
        @Result(name = "success", location = "/member/register.jsp")
    })
    public String register() {
        return SUCCESS;
    }
    
    @Action(value = "viewOrders", results = {
        @Result(name = "success", location = "/member/viewOrders.jsp")
    })
    public String viewOrders() {
        Map session = ActionContext.getContext().getSession();
        Customer customer = (Customer) session.get("currentCustomer");
        
        TOrderDAO tOrderDAO = new TOrderDAO();
        orderList = tOrderDAO.getOrdersByCustomerID(customer.getIdCustomer());
        
        return SUCCESS;
    }
    
    @Action(value = "viewProfile", results = {
        @Result(name = "success", location = "/member/customerProfile.jsp")
    })
    public String viewProfile() {
        return SUCCESS;
    }
}